package com.nmf.site.common;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;

public class WebClientUtils {
	public static WebClient createWebClinet() {
		final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52);  
		  
        webClient.getOptions().setThrowExceptionOnScriptError(false);  
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);  
        // final WebClient webClient=new  
        // WebClient(BrowserVersion.FIREFOX_10,"http://myproxyserver",8000);  
        // //使用代理  
        // final WebClient webClient2=new  
        // WebClient(BrowserVersion.INTERNET_EXPLORER_10);  
        // 设置webClient的相关参数  
        webClient.getOptions().setJavaScriptEnabled(true);  
        webClient.getOptions().setActiveXNative(false);  
        webClient.getOptions().setCssEnabled(false);  
        webClient.getOptions().setThrowExceptionOnScriptError(false);  
        webClient.waitForBackgroundJavaScript(5*1000);  
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());  
//          
//        webClient.getOptions().setJavaScriptEnabled(true);    
        /* 
        webClient.setJavaScriptTimeout(3600*1000);   
        webClient.getOptions().setRedirectEnabled(true);   
        webClient.getOptions().setThrowExceptionOnScriptError(true);   
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);   
        webClient.getOptions().setTimeout(3600*1000);   
        webClient.waitForBackgroundJavaScript(600*1000);   
        */  
//      webClient.waitForBackgroundJavaScript(600*1000);  
//        webClient.setAjaxController(new NicelyResynchronizingAjaxController()); 
		
		return webClient;
	}
}
